<?php session_start(); ?>
<?php
include('../ketnoi.php');

if (!$_SESSION['user']) header("location: index.php"); // nếu biến session['banguyen'] chưa có thì trở về trang đăng nhập, copy dòng này vào trang nào muốn bảo vệ bằng mật khẩu
?>
<style type="text/css">
<!--
.error, .notice, .success {padding:.8em;margin:auto; margin-bottom:.5em;border:2px solid #AAF;width:570px;text-align: center}
.error {background: #ECECFF;color: red;border-color:#AAF;}
-->
</style>
<script type="text/javascript" src="scripts/joomla.js"></script>
<div class="m">
<?php
$shop=$dulieu;
if($_GET['action']=='view' && $_GET['option']=='com_order_status')
	{
		$sql = "SELECT * FROM `".$shop."`.`truonglk`  order by MaTLK asc";  	
		$ketqua = mysql_query($sql) or die ('khong tim thay du lieu');	
		$tong=mysql_num_rows($ketqua);	
?>
<div id="menu">
	<div style="float: right;">
	<div class="icon1">
<a  class="toolbar" href="index.php"><img src="images/toolbar/icon-32-cancel.png" alt="Remove"><br><span>Cancel</span></a>
	</div>
	</div>

	
	<div style="float: right;">
	<div class="icon1">
<a class="toolbar" href="?option=com_order_status&action=insert"><img src="images/toolbar/icon-32-new.png" alt="New"><br><span>New</span></a>
	</div>
	</div>
</div>

<div class="header" style="background: url(images/dashboard/countries.png) no-repeat scroll 0% 0% transparent; text-indent: 30px; line-height: 50px;">
  <h2 style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;Các đơn vị liên kết </h2>
</div><br /><br />
<form name="adminForm" action="" method="post">
					
					<input name="option" value="com_order_status" type="hidden">
					<input name="boxchecked" type="hidden">
					<input name="task" value="" type="hidden">
					<input name="func" value="" type="hidden">


<table class="adminlist"  width="100%">
<tbody><tr ><th width="30" class="title">#</th>
<th width="40" class="title"><input name="toggle" value="" onClick="checkAll(<?php echo $tong; ?>)" type="checkbox"></th>
<th class="title" width="384" align="center">Đơn vị</th>
<th class="title" width="428" align="center"> Liên kết</th> 
<th class="title" width="223" align="center"> Hình ảnh </th>
<th width="85" class="title"> Sửa</th>
<th  class="title" width="97"> Xóa</th>
</tr>
 <?php 
	$stt=0;
	$t=0;
   while($dongDL = mysql_fetch_array($ketqua))
	  { 
  ?>
  
<tr class="row<?php echo $t ?>">
<td><?php echo $stt+1 ?></td>
<td align="center"><input id="cb<?php echo $stt ?>" name="product_id[<?php echo $dongDL['MaTLK']?>]" value="<?php echo $dongDL['MaTLK']?>" onClick="isChecked(this.checked);" type="checkbox"></td>
<td style="padding-left:50px"><?php echo $dongDL['TenT']?></td>
<td style="padding-left:50px"><a href="<?php echo $dongDL['LinkLK'] ?>" target="_blank"><?php echo $dongDL['LinkLK'] ?></a></td>
<td class="order" align="center"><img src="../upload/<?php echo $dongDL['DuongDan']?>" width="52" height="54" /></td>
<td align="center"><a  href="?option=com_order_status&action=update&amp;id=<?php echo $dongDL['MaTLK'] ?>"><img src="images/edit_f2.png" width="20" height="20" alt="Edit" border="0"></a></td>
<td  align="center"><a class="toolbar" href="?option=com_order_status&action=delete&amp;id=<?php echo $dongDL['MaTLK'] ?>" onClick="return confirm('Bạn có chắc chắn muốn xóa?');"><img src="images/delete_f2.png" width="20" height="20"alt="Delete"  align="middle" border="0"></a></td>
</tr>
	 <?php
	 $stt=$stt+1;
	 if($t==0)$t=1;
	 else $t=0;
	  }//ket thuc ham while in du lieu
	  ?>
<tr>
<td colspan="7"><table width="100%"><tr>
<td width="45%" align="right" nowrap="nowrap">Display #</td><td width="10%">
<select class="inputbox" name="limit" size="1" disabled="disabled">
<option><?php echo $tong; ?></option>
</select>
</td><td width="45%" align="left" nowrap="nowrap"><?php if($tong >0){?>Results 1 - 
<?php echo $tong;?> of <?php echo $tong; }?></td></tr>
</table></td>
</tbody></table>
</form>
<?php
}//ket thuc view

if($_GET['action']=='delete' && $_GET['option']=='com_order_status')
	{
		  $sql = "Delete from `".$shop."`.`truonglk` where MaTLK = '".$_GET['id']."'";
		  $delete = mysql_query($sql);
          echo"<script language=javascript>window.location='index.php?option=com_order_status&action=view';</script>";
	  }// ket thuc kiem tra action Delete
	  
if($_GET['action']=='insert' && $_GET['option']=='com_order_status')
{
	
if(isset($_POST['s1'])){
	$error="";
	if($_POST['s1']=="" || $_POST['s2']=="" || $_FILES["s3"]["name"]==''){
	  $error="Vui lòng nhập đầy đủ các field.";
    }else{
		move_uploaded_file($_FILES["s3"]["tmp_name"],"../upload/" . $_FILES["s3"]["name"]);
	    $sql = "INSERT INTO `".$shop."`.`truonglk` (`TenT`,`LinkLK`,`DuongDan`) VALUES ('".$_POST['s1']."','".$_POST['s2']."','".$_FILES["s3"]["name"]."');";
		$insert = mysql_query($sql);
        echo"<script language=javascript>window.location='index.php?option=com_order_status&action=view';</script>";
	}//ket thuc kiem tra nhap day du
}//ket thuc luu 
	?>
	<div id="menu">
	<div style="float: right;">
	<div class="icon1">
<a  class="toolbar" href="?option=com_order_status&action=view"><img src="images/toolbar/icon-32-cancel.png" alt="Remove"><br><span>Cancel</span></a>
	</div>
	</div>
	
	<div style="float: right;">
	<div class="icon1">
<a class="toolbar" onClick="adminForm2.submit();"><img src="images/toolbar/icon-32-save.png"  alt="New"><br><span>Save</span></a>
	</div>
	</div>
</div>

<div class="header" style="background: url(images/dashboard/countries.png)  no-repeat scroll 0% 0% transparent; text-indent: 30px; line-height: 50px;">
  <h2 style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;Các đơn vị liên kết: [ Thêm mới ]</h2>
</div><br /><br />

<?php
	if($error!=""){
	?>
	 <div class="error" align="center"><img src='../images/cancel_f2.png' width='10px' height='10px'/> <?php echo $error ?></div>
  <?php
  }
?>
	<form name="adminForm2" action="" method="post" enctype="multipart/form-data">

<div style="height: auto; width: 1012px;" id="ext-gen37">
<div class="tab-page" id="info-page">
<table class="adminform">
	<tbody><tr> 
   		<td width="689" valign="top">
			<table width="100%" border="0">
      			<tbody><tr> 
       				<td colspan="2" align="left"><h3><span style="margin: 0px;">Đơn vị</span></h3></td>
    			</tr>
    			<tr class="row0"> 
      				<td width="29%"><div style="text-align: right; font-weight: bold;">
   					  Tên :</div>      				</td>
      				<td width="71%" style="padding-left:15px"> 
       				  <input style="width:250px; height:20px"  name="s1" size="32" maxlength="255" type="text">      				</td>
    			</tr>
				<tr class="row1"> 
      				<td width="29%"><div style="text-align: right; font-weight: bold;">
   					  Liên kết:</div>      				</td>
      				<td width="71%" style="padding-left:15px"> 
       				  <input style="width:250px; height:20px"  name="s2" size="32" maxlength="255" type="text">      				</td>
    			</tr>

				<tr class="row0"> 
      				<td width="29%"><div style="text-align: right; font-weight: bold;">Hình ảnh:</div>      				</td>
      				<td width="71%" style="padding-left:15px"> <input name="s3" type="file" style="min-width:250px; height:23px" /> </td>
    			</tr>
    			  <tr class="row0"> 	    
		      		<td valign="top" width="29%">&nbsp;</td>
		      		<td width="71%">&nbsp;</td>		    
	    			</tr>
  			    </tbody></table>
 		</td>
  	</tr>
</tbody></table>

</div>
</div>
</form>
<?php
}// ket thuc kiem tra action insert



if($_GET['action']=='update' && $_GET['option']=='com_order_status')
{
    if($_GET['id'] !=""){
	    $_SESSION['id']= $_GET['id'];
	}
		$sql ="SELECT * from `".$shop."`.`truonglk` where MaTLK = '".$_SESSION['id']."'";
		$ketqua = mysql_query($sql);
		$dulieu = mysql_fetch_array($ketqua);
		
if(isset($_POST['ts1'])){ 
	$error="";
	if($_POST['ts1']=="" || $_POST['ts2']=="" ){   	 	 	
	  $error="Vui lòng nhập đầy đủ các field.";
    }else{ 
	   if($_FILES["ts3"]["name"]==''){ $_FILES["ts3"]["name"]=$dulieu['DuongDan'];} else{ move_uploaded_file($_FILES["ts3"]["tmp_name"],"../upload/" . $_FILES["ts3"]["name"]);}  
	     $sql = "UPDATE `".$shop."`.`truonglk` SET  `TenT` = '".$_POST['ts1']."',`LinkLK` = '".$_POST['ts2']."', `DuongDan` ='".$_FILES["ts3"]["name"]."' WHERE `truonglk`.`MaTLK` = '".$_SESSION['id']."'";
		 $update = mysql_query($sql) or die($sql);
         echo"<script language=javascript>window.location='index.php?option=com_order_status&action=view';</script>";
	}
}
	?>
<div id="menu">
	<div style="float: right;">
	<div class="icon1">
<a  class="toolbar" href="?option=com_order_status&action=view"><img src="images/toolbar/icon-32-cancel.png" alt="Remove"><br><span>Cancel</span></a>
	</div>
	</div>
	
	<div style="float: right;">
	<div class="icon1">
<a class="toolbar" onClick="adminForm3.submit();"><img src="images/toolbar/icon-32-save.png"  alt="New"><br><span>Save</span></a>
	</div>
	</div>
</div>

<div class="header" style="background: url(images/dashboard/countries.png)  no-repeat scroll 0% 0% transparent; text-indent: 30px; line-height: 50px;">
  <h2 style="margin: 0px;">&nbsp;&nbsp;&nbsp;&nbsp;Đơn vị liên kết: [Sửa]</h2>
</div><br /><br />
<?php
	if($error!=""){
	?>
	 <div class="error" align="center"><img src='../images/cancel_f2.png' width='10px' height='10px'/> <?php echo $error ?></div>
  <?php
  }
?>
		<form name="adminForm3" action="" method="post" enctype="multipart/form-data">

<div style="height: auto; width: 1012px;" id="ext-gen37">
<div class="tab-page" id="info-page">
<table class="adminform">
	<tbody><tr> 
   		<td width="689" valign="top">
			<table width="100%" border="0">
      			<tbody><tr> 
       				<td colspan="2" align="left"><h3>Đơn vị: <?php echo $dulieu['TenT'] ?></h3></td>
    			</tr>
    			<tr class="row0"> 
      				<td width="29%"><div style="text-align: right; font-weight: bold;">
   					  Tên :</div>      				</td>
      				<td width="71%" style="padding-left:15px"> 
       				  <input style="width:250px; height:20px"  name="ts1" size="32" maxlength="255" type="text" value="<?php echo $dulieu['TenT'] ?>">      				</td>
    			</tr>
				<tr class="row1"> 
      				<td width="29%"><div style="text-align: right; font-weight: bold;">
   					  Liên kết:</div>      				</td>
      				<td width="71%" style="padding-left:15px"> 
       				  <input style="width:250px; height:20px"  name="ts2" size="32" maxlength="255" type="text" value="<?php echo $dulieu['LinkLK'] ?>">      				</td>
    			</tr>
									<tr class="row1"> 
      				<td width="29%"><div style="text-align: right; font-weight: bold;">Hình ảnh:</div>      				</td>
      				<td width="71%" style="padding-left:15px"><input name="ts3" type="file" style="min-width:250px; height:23px" /></td>
    			</tr>
    			  <tr class="row0"> 	    
		      		<td valign="top" width="29%">&nbsp;</td>
		      		<td width="71%">&nbsp;</td>		    
	    			</tr>
  			    </tbody></table>
 		</td>
  	</tr>
</tbody></table>

</div>
</div>
</form>
<?php
}//ket tuc update
 
?>